package org.anddev.andengine.entity.particle.modifier;

import org.anddev.andengine.entity.particle.Particle;

/**
 * Kill particles when they hit given bounds
 * 
 * @author adam
 *
 */
public class CullOnBoundsModifier implements IParticleModifier {

	public final float mBoundsMaxX;
	public final float mBoundsMaxY;

	public final float mBoundsMinX;
	public final float mBoundsMinY;
	
	public CullOnBoundsModifier (float pBoundsMaxX, float pBoundsMaxY) {
		mBoundsMaxX = pBoundsMaxX;
		mBoundsMaxY = pBoundsMaxY;

		mBoundsMinX = 0;
		mBoundsMinY = 0;
	}
	
	public CullOnBoundsModifier (float pBoundsMinX, float pBoundsMinY, float pBoundsMaxX, float pBoundsMaxY) {
		mBoundsMaxX = pBoundsMaxX;
		mBoundsMaxY = pBoundsMaxY;

		mBoundsMinX = pBoundsMinX;
		mBoundsMinY = pBoundsMinY;
	}
	
	@Override
	public void onUpdateParticle(Particle pParticle) {
		final float pX = pParticle.getX();
		final float pY = pParticle.getY();
		if ((pX < mBoundsMinX) || (pX > mBoundsMaxX)
		  ||(pY < mBoundsMinY) || (pY > mBoundsMaxY)) {
			pParticle.setDead(true);
		}
	}

	@Override
	public void onInitializeParticle(Particle pParticle) {
		// TODO Auto-generated method stub
		
	}

}
